package net.dengzixu.java.homework.period9;

import java.util.Scanner;

/**
 * @author Deng Zixu <admin@dengzixu.com>
 */
public class Period9Homework3 {
    public static void main(String[] args) {
        System.out.print("请输入数字: ");

        Scanner scanner = new Scanner(System.in);

        int inputNum = scanner.nextInt();
        if (inputNum < 6) {
            System.out.println("所输入的数字内不包含完全数。");
        }
        System.out.print("所输入的数字内完全数有: ");

        for (int i = 7; i <= inputNum; i++) {
            if (isPerfectNumber(i)) {
                System.out.print(" " + i);
            }
        }
    }

    public static boolean isPerfectNumber(int num) {
        int summation = 0;
        for (int i = 1; i < num - 1; i++) {
            if (num % i == 0) {
                summation += i;
            }
        }
        return num == summation;
    }
}
